package cn.tedu.recruitmentwebsite.employee.controller;

import cn.tedu.recruitmentwebsite.employee.pojo.dto.QueryParam;
import cn.tedu.recruitmentwebsite.employee.pojo.dto.SavePositionParam;
import cn.tedu.recruitmentwebsite.base.pojo.vo.JobVO;
import cn.tedu.recruitmentwebsite.base.response.JsonResult;
import cn.tedu.recruitmentwebsite.employee.service.PositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Slf4j
@RestController
@RequestMapping("/employer/position/")
public class PositionController {
    @Autowired
    private PositionService positionService;


    /**
     * 查询职位
     * @param queryParam
     * @return
     */
    @GetMapping("getAllPosition")
    public JsonResult getAllPositions(QueryParam queryParam){
        log.debug("查询职位-入参:queryParam={}",queryParam);
        List<JobVO> jobs = positionService.getAllPosition(queryParam);
        log.debug("查询职位-出参:jobs={}",jobs);
        return JsonResult.ok(jobs);
    }

    /**
     * 新增岗位
     * @param savePositionParam
     * @return
     */
    @PostMapping("save")
    public JsonResult savePosition(SavePositionParam savePositionParam){
        log.debug("新增岗位-入参:savePositionParam={}",savePositionParam);
        positionService.savePosition(savePositionParam);
        return JsonResult.ok();
    }

    /**
     * 根据id查询岗位
     * @param id
     * @return
     */
    @GetMapping("getPositionById")
    public JsonResult getPositionById(Long id){
        log.debug("根据id查询岗位-入参:id={}",id);
        JobVO jobVO = positionService.getPositionById(id);
        log.debug("根据id查询岗位-出参:jobVO={}",jobVO);
        return JsonResult.ok(jobVO);
    }

    @PostMapping("delete/{id}")
    public JsonResult deletePosition(@PathVariable Long id){
        log.debug("根据id删除岗位-入参:id={}",id);
        positionService.deletePosition(id);
        return JsonResult.ok();
    }

    @PostMapping("updateStatus/{id}")
    public JsonResult updatePosition(@PathVariable Long id){
        log.debug("根据id修改岗位状态-入参:id={}",id);
        positionService.updatePosition(id);
        return JsonResult.ok();
    }
}
